/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication1;

/**
 *
 * @author admin
 */
public class TrafficLight {
    private int changingNormalLightTime;
    private int changingYellowLightTime;
    private int xPos;
    private int yPos;
    private int countNormalLight;
    private int countYellowLight;

    private String[] states = {"G","Y","R"};
    private int currentState;

    public TrafficLight(int startState, int changingNormalLightTime, int changingYellowLightTime){
            this.changingNormalLightTime=changingNormalLightTime;
            this.changingYellowLightTime=changingYellowLightTime;

            this.countNormalLight = this.changingNormalLightTime;
            this.countYellowLight = this.changingYellowLightTime;
            this.currentState = startState;
    }

    public String changeState(){
        if(countNormalLight==0){
            currentState++;
            if(currentState==3)
                currentState=0;
            countNormalLight=changingNormalLightTime;
        }

        if(countYellowLight==0){
            currentState++;
            countYellowLight=changingYellowLightTime;
        }

        if(currentState==0 || currentState==2){
            countNormalLight--;
        }
        else
            countYellowLight--;

        return states[currentState];
    }

    public String getState(){
        return states[currentState];
    }

    void setPosition(int y, int x) {
        this.xPos = x;
        this.yPos = y;
    }

    public int getxPos() {
        return xPos;
    }

    public int getyPos() {
        return yPos;
    }

    
}
